<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">用户信息修改</block>
		</cu-custom>
		<view class="cu-form-group">
			<view class="title">原密码</view>
			<input placeholder="请输入原密码" name="input" v-model="oldpassword"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">新密码</view>
			<input placeholder="请输入新密码" name="input" v-model="newpassword"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">确认密码</view>
			<input placeholder="请再次输入新密码" name="input" v-model="repeatpassword"></input>
		</view>
		<button class="cu-btn bg-blue lg" style="width:100%" @click="subbmit()">点击提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				oldpassword:"",
				newpassword:"",
				repeatpassword:""
				
			}
		},
		methods: {
			subbmit(){
				//进行数据格式得校验
				let that = this
				if(this.oldpassword === ""){
					uni.showToast({title:"旧密码不能为空",icon:"none"})
					return
				}
				if(this.newpassword === ""){
					uni.showToast({title:"新密码不能为空",icon:"none"})
					return
				}
				if(this.repeatpassword != this.newpassword){
					uni.showToast({title:"请确认两次输入密码一致",icon:"none"})
					return
				}
				//准备进行提交 应先取到缓存中得id
				uni.getStorage({
				   key: 'id',
				   success: function (res) {
				       //console.log(res.data)
					   let data = {
						   id:res.data,
						   oldpassword:that.oldpassword,
						   newpassword:that.newpassword,
					   					   
					   }
					   uni.request({
					   	url:"http://localhost/stuapi/StuChangePassword",
					   	data:data,
					   	method:"POST",
					   	header:{'content-type':'application/x-www-form-urlencoded'},
						success: (res) => {
							let code = res.data.code;
							if(code == 200){
							}
							else{
							}
							uni.showToast({ title:res.data.message, icon:"none",})
							
						}
						
						
						
				       });
				   },
						fail:function(){
							uni.showToast({title:"登录状态失效",icon:"none"})
							return
						}
				   });
				   
				   
			},
			
		}
	}
</script>

<style>

</style>
